Removes the LAST item of target AND gives it back to you. If target is empty, nothing is removed and a plain default value comes back instead (0, 0.0, false, an empty string or `nothing`, depending on what the list holds) - target never crashes. Check list_length(target) first if you need to tell "the last item really was this" apart from "the list was empty".
list_pop(target) -> element| Name | Type |
|---|---|
target | list |
element
Takes the LAST item out of target and gives it back to you. Use it when you need the item you just removed: the name of the thing you dropped, the number you took off the pile.
If target is empty, nothing is removed and a plain "nothing here" value comes back instead (0, 0.0, false, an empty string or nothing, depending on what the list holds). The game never stops. Check list_length(target) first if you need to tell "the last item really was 0" apart from "the list was empty".
To take out an item from the front or the middle, read it first and then use list_remove, which only removes and says whether it worked.
/// @type {list<int>}
var scores = [10, 20, 30];
var last = list_pop(scores); // 30 - scores is now [10, 20]The vector's back() then pop_back() - O(1), with the empty case checked first so neither is ever called on an empty vector. The fallback is the same small compiled-in lambda stack_pop uses.